package com.hubusugon.st.test.controller;

import com.hubusugon.st.test.bean.Person;
import com.hubusugon.st.test.service.PersonService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class PersonController {
    @Resource
    PersonService personService;
    @RequestMapping("/findPerson")
    @ResponseBody
    public List<Person> findPerson(){
        List<Person> personList = personService.findPerson();
        return personList;
    }

    @ResponseBody
    @RequestMapping("/addPerson")
    public String addPerson(@RequestBody Person person){  //!!@RequestBody必须加 不然前端的值传不进去
        String result = personService.addPerson(person);
        return  result;
    }

    @ResponseBody
    @RequestMapping("/deletePerson")
    public String deletePerson(@RequestBody Person person) {
        String result = personService.deletePerson(person);
        return result;
    }

    @ResponseBody
    @RequestMapping("/updatePerson")
    public  String updatePerson(@RequestBody Person person){
        String result = personService.updatePerson(person);
        return  result;
    }
}
